<?php

require_once 'random.php';

if (!($rs = $_POST['rs'])) {
    $rs = "\n";
}

if (!($site_id = $_POST['site_id'])) {
    $site_id = 123;
}


$num = Random::Int(5, 20);


$rows = array ();

$delimiter = ';';
$enclosure = '"';

$headers = array (
    'transaction_type',
    'transaction_id',
    'customer_id',
    'site_id',
    'product_id',
    'name',
    'email',
    'customer_ip',
    'date',
    'total',
    'cs1',
    'cs2',
    'cs3',
    'username',
    'password',
    'payment_type',
    'reference',
);

for ($i=0; $i<$num; $i++)
{
    foreach ( $headers as $header )
    {
        $value = null;

        switch ($header)
        {
        case 'transaction_type':
            $value = Random::Enum(array('VOID', 'CAPTURE', 'REFUND'));
            break;

        case 'transaction_id':
            $value = Random::Int(785, 1556);
            break;

        case 'customer_id':
            $value = Random::Int(785, 1556);
            break;

        case 'site_id':
            $value = $site_id;
            break;

        case 'product_id':
            $value = Random::Int(785, 1556);
            break;

        case 'name':
            $value = Random::FullName();
            break;

        case 'email':
            $value = Random::Email();
            break;

        case 'customer_ip':
            $value = Random::IP();
            break;

        case 'date':
            $value = Random::DateTime(time()-10*24*60*60, time());
            break;

        case 'total':
            $value = Random::Decimal(6, 2);
            break;

        case 'cs1':
        case 'cs2':
            $value = Random::Login();
            break;

        case 'cs3':
            $value = Random::Password() . Random::Enum(array('', '', '', '', '\\"', '', '', ''));
            break;

        case 'username':
            $value = Random::Login();
            break;

        case 'password':
            $value = Random::Password();
            break;

        case 'payment_type':
            $value = Random::Enum(array('VOID', 'CAPTURE', 'REFUND'));
            break;

        case 'reference':
            $value = Random::Int(785, 1556);
            break;
        }

        $rows[$i][] = $value;
    }

}

$csv = array ();
foreach ( $rows as $row )
{
    $line = array ();
    foreach ( $row as $value )
    {
        $line[] = $enclosure.str_replace($enclosure, $enclosure.$enclosure, ( $value)).$enclosure;
    }
	$csv[] = implode($delimiter, $line);
}
$csv = implode($rs, $csv);

echo $csv;

?>